<?php
class NewsMainController extends ApplicationViewableController  
{
    /**
     * @var News
     */
    protected $news;
    
    public function prepare()
    {
        $id = Env::getParam('id');
        $words_url = Env::getParam('words_url');
        
        $NewsModel = new NewsModel();

        $news = null;
        if ($words_url) {
            $news = $NewsModel->get(md5($words_url), 'words_url_hash');
        } elseif ($id) {
            $news = $NewsModel->get($id);
        }
        
        if (!$news) {
            throw new HTTP404Exception();
        }
        $this->news = $news;
        
        define('PAGE_TITLE', ' | Новости | ' . htmlspecialchars($news->getTitle()));
        define('META_DESC', htmlspecialchars($news->getDescription()));
        
        $SeoText2Keywords = new SeoText2Keywords(array($news->getTitle(), $news->getDescription()), new SeoKeywordFilter());
        define('META_KEY', $SeoText2Keywords->__toString());
        
        $this->view->assign('news', $news);
    }
    
    /**
     * Возвращает выбранную новость
     *
     * @return News
     */
    public function getNews()
    {
        return $this->news;
    }
}